
import BaseSingleClass from "../base/BaseSingleClass";

export default class SensorsHelper extends BaseSingleClass {
    private _sensors = null;
    private _time = 0;
	private _date = null;
	private _nowView=null;
    constructor() {
		super();
		this._sensors = window['sensorsDataAnalytic201505']
		const params=window.location.host=='apph5.fenzhidao.com'?'project=production&token=92c45f523c806f01':'project=default&token=92c45f523c806f01'
		const url='fenzhidao.datasink.sensorsdata.cn/sa?'+params
		//const sensors = window['sensorsDataAnalytic201505']
		if(window.location.host!='apph5.fenzhidao.com'){
		this._sensors.init({
		server_url: 'https://'+url,
		heatmap:{clickmap: 'not_collect',scroll_notice_map:'not_collect'},
		is_track_single_page:true,
		use_client_time:true,
		send_type:'beacon',
				show_log: true,
				app_js_bridge: {
					white_list: ['http://' + url, 'https://' + url]
				},   
		});
		const platform_type=true?"H5_Z3平板":"H5";
		this._sensors.registerPage({platform_type: platform_type})
		this._sensors.quick('autoTrack')}
	}
    WebClick(id: string,content: string) {
		if(!this._sensors||!id) return
		this._sensors.track('$WebClick', {
			custom_element_id: id,
			$element_content: content
		});
	}
    pageview(id?: string) {
		if (!this._sensors||!id) return
		this._sensors.track('$pageview', {
			custom_page_id: id,
			$title: this.getEnumName('', id)
		});
		this.WebStay()
		this._date = Date.now();
		this._nowView = this.getEnumName('', id);
	}
    WebStay() {
		if (!this._sensors||!this._nowView) return
		let time = Date.now();
		let t = time - this._date;
		this._sensors.track('$WebStay', {
			$event_duration: t / 1000,
			$title: this._nowView
		});
	}
    //根据枚举的值获得枚举的名称
	private getEnumName(enumName: any, value: any) {
		var enumObj = eval(enumName);
		for (var key in enumObj) {
			if (enumObj[key] == value) {
				return key;
			}
		}
		return "";
	}
}
//this.mall.active = !this.hasStr(location.search, "device");